package lib

import (
	"algorithms/ds"
)

func init() {
	Probs = append(Probs, Problem{
		Num:         100,
		Discription: "判断两颗树是否相同",
		Level:       1,
		Labels: map[string]int{
			"回溯":  1,
			"二叉树": 1,
		},
	})
}

func IsSameTree(p *ds.TreeNode, q *ds.TreeNode) bool {
	//优先判断是否同时为nil
	if p == nil && q == nil {
		return true
	}

	//是否有且只有一者为nil
	if p == nil || q == nil {
		return false
	}

	return p.Val == q.Val && IsSameTree(p.Left, q.Left) && IsSameTree(p.Right, q.Right)
}
